﻿@model HomeStayWebCP.Models.BusinessObject.PostObject
     
@{
    ViewBag.Title = "Step 1";
}
<link href="../../Content/Styles/checkboxstyle.css" rel="stylesheet" type="text/css" />

@{
    if (HttpContext.Current.Session["username"] != null)
    {
        <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
        <script type="text/javascript">
    //****Hoagdx - Begin Script****

            var Chmap;
            var obj = null;

            function mapClick(location) {
                if (obj != null) {
                    obj.setMap(null);
                }
                var marker = new google.maps.Marker({
                    position: location,
                    map: Chmap
                });
                obj = marker;
                Chmap.setCenter(marker.getPosition());

                var infom = location.lat() + ',' + location.lng();
                document.getElementById("House_Ordinate").value = infom;
            }

            function search() {
                var addressField = document.getElementById('House_AddressDetail');
                var geocoder = new google.maps.Geocoder();
                //alert("go to search");
                //alert(addressField.value);
                geocoder.geocode(
                    { 'address': addressField.value },
                    function(results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            var loc = results[0].geometry.location;
                            // use loc.lat(), loc.lng()
                            var myLatlng = new google.maps.LatLng(loc.lat(), loc.lng());
                            mapClick(myLatlng);
                            Chmap.setZoom(12);

                            //alert("Founded");
                        } else {
                            alert("Your address cann't be found.");
                        }
                    }
                );
            }

            ;

            function search1() {
                //alert("go search 1");
                var addressField = document.getElementById('address_recommend');
                var geocoder = new google.maps.Geocoder();
                //alert("go to search");
                //alert(addressField.value);
                geocoder.geocode(
                    { 'address': addressField.value },
                    function(results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            var loc = results[0].geometry.location;
                            // use loc.lat(), loc.lng()
                            var myLatlng = new google.maps.LatLng(loc.lat(), loc.lng());
                            mapClick(myLatlng);
                            Chmap.setZoom(10);

                            //alert("Founded");
                        } else {
                            alert("Your address can not be founded." + status);
                        }
                    }
                );
            }

            ;

            function initializes() {
                //alert('go1');

                //declare points on Map
                var pointCenter = null;
                pointCenter = new google.maps.LatLng(16.280305, 107.519529);
                //alert('g4');
                //declare Map properties
                var ChmapProp = {
                    center: pointCenter,
                    zoom: 6,
                    //disableDefaultUI:false, //dissable UI control
                    panControl: true,
                    //zoomControl: true,
                    //zoomControlOptions: {
                    //style: google.maps.ZoomControlStyle.LARGE,
                    //position: google.maps.ControlPosition.BOTTOM_LEFT
                    //},
                    mapTypeControl: true,
                    scaleControl: false,
                    streetViewControl: false,
                    overviewMapControl: false,
                    rotateControl: false,
                    disableDoubleClickZoom: true,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

                Chmap = new google.maps.Map(document.getElementById("googleMap"), ChmapProp);
                //add event listener when user click to somewhere on map
                google.maps.event.addListener(Chmap, 'dblclick', function(event) { mapClick(event.latLng); });
            }

//end initialize   

            function placeMarker() {
                if (mapZoom == map.getZoom()) {
                    var marker = new google.maps.Marker({
                        position: location,
                        map: map
                    });
                }
            }

            window.onload = function() {
                initializes();
            }
            google.maps.event.addDomListener(window, 'load', initializes);

            $(function () {
                var selectedtypehouse = $("#TypeOfHouseID").val();
                if (selectedtypehouse == 1) {
                    $('#SearchHomestay').css("display", "block");
                   
                }
                $("#ddlprovince").change(function (evt) {
                    var txt = $("#ddlprovince option:selected").text();
                    //alert(txt);

                    $("#address_recommend").val(txt);
                    search1();
                    var d = document.getElementById("ddlprovince").i;
                    {
                        var selectedProvince = $(this).val();
                        if (selectedProvince == '')
                            selectedProvince = -1;
                        if (selectedProvince != null) {
                            $.ajax({
                                url: "/Posts/GetDistrictCbb",
                                type: 'POST',
                                data: { province: selectedProvince },
                                success: function (response) {
                                    $("#ddldistrict").replaceWith(response)

                                },
                                error: function (xhr) {
                                    alert("Something went wrong, please try again");
                                }
                            });

                        } else {


                        }
                    }
                });
                $('#TypeOfHouseID').change(function (evt) {
                    var selectedhousetype = $(this).val();
                    if (selectedhousetype == 1) {
                        $('#SearchHomestay').css("display", "block");


                    } else {
                        $('#SearchHomestay').css("display", "none");
                        var checkboxes = document.getElementsByName("HomeStayTypeID");
                        for (var i = 0; i < checkboxes.length; i++) {
                            // And stick the checked ones onto an array...
                            document.getElementsByName("HomeStayTypeID")[i].checked = false;
                        }
                    }
                });
            });
        //End Script
</script>
  
        <style>
            #container
            {
                background-color: white;
                min-height: 1000px !important;
            }
            #headbox
            {
                height: 30px;
                background-color: #c30;
                text-align: left;
                font-size: 1.5em;
                padding-left: 10px;
                color: white;
                padding-top: 5px;
            }
            .infobox
            {
                width: 1120px;
                height: 275px;
                margin: 0 auto;
                background-color: #D2D29F;
                margin-top: 10px;
                border-radius: 5px 5px 5px 5px;
                padding-bottom: 10px;
            }
            .leftlabel
            {
                float: left;
                width: 150px;
                margin-top: 10px;
                margin-left: 10px;
                font-size: 1.1em;
                color: black;
            }
            .editor-field
            {
                float: left;
                margin-top: 10px;
                margin-left: 10px;
            }
            .field
            {
                clear: both;
            }
            #SearchHomestay
            {
                margin-top: 20px;
                margin-left: 150px;
                font-size: 1.1em;
            }
            .headerbox
            {
                width: 1120px;
                height: 20px;
                margin: 0 auto;
                background-color: whitesmoke;
                border-radius: 5px 5px 5px 5px;
            }
            input, textarea
            {
                color: black !important;
            }
            .field-validation-error
            {
                float: left !important;
                color: red;
            }
            #btnmap
            {
                position: absolute;
                top: 515px;
                left: 200px;
                width: 80px;
                background-color: sienna;
                color: whiteSmoke !important;
                height: 28px;
                z-index: 1;
            }
            .field-validation-valid
            {
                color: darkred;
            }
        </style>
        <button onclick="search();" id="btnmap">Locate</button>
        using (Html.BeginForm("CreateStep1", "Posts", FormMethod.Post, new { id = "form" }))
        {
             @Html.ValidationSummary(true)
             <div id="headbox" class="rounded-corners">Step 1:General Information</div>
             <div id="generalinfo" class="infobox" style="position: relative">
                 @* <div class="headerbox">Post Information</div>*@
                 @*Title*@
                 <div class="field">
                     <span class="leftlabel">Title (*)</span>
                     <div class="editor-field">
                         @Html.TextBoxFor(model => model.Title, new { style = "width:700px" })
                         @Html.ValidationMessageFor(model => model.Title)
                     </div>
                     <div style="top: 15px;position: absolute;right: 25px;">(Title is limited 10-100 characters)</div>
                 </div>
                 @*Introduction*@
                 <div class="field">
                     <span class="leftlabel">Introduction</span>
                     <div class="editor-field">
                         @Html.TextAreaFor(model => model.Content, new { style = "width:800px;height:80px" })
                         @Html.ValidationMessageFor(model => model.Content)
                     </div>
                 </div>
                 @*Type of Homestay*@
                 <div class="field">
                     <span class="leftlabel">Type of House (*)</span>
                     <div class="editor-field" style="">
                         @Html.DropDownListFor(model => model.House.TypeOfHouseID, (IEnumerable<SelectListItem>)ViewBag.TypeofHouse, "Select-Type", new { style = "width:240px", id = "TypeOfHouseID" })
                         @Html.ValidationMessageFor(model => model.House.TypeOfHouseID)
                     </div>
                 </div>
                 @* Check List Homestay*@
                 <div class="field" id="SearchHomestay" style="display: none">
                     <div id="checklist" style="position: absolute;left: 450px;top: 155px;width: 100px;">
           
                         @{
            foreach (var item in (IEnumerable<SelectListItem>)ViewBag.HomeStayTypeID)
            {
@*                                 <span class="leftspace" style="color: black; margin-left: 20px;">@item.Text </span>*@
@*                                 <input type="checkbox" name="HomeStayTypeID" id="@item.Value" value="@item.Value"  />*@
                              <div class="custom-checkbox">
                                   <input type="checkbox" id="@item.Value" value="@item.Value" name="HomeStayTypeID">
                                   <label for="@item.Value"><span class="box"></span>@item.Text</label>
                              </div>
            }
                         }
                     </div>
                 </div>
             </div>

             <div id="region" class="infobox" style="height: 150px">
                 @*Title*@
                 <div class="field">
                     <span class="leftlabel">Province(*)</span>
                     <div class="editor-field">
                
                         @Html.DropDownListFor(model => model.House.ProvinceID, (IEnumerable<SelectListItem>)ViewBag.Province, "Select-Province", new { id = "ddlprovince", style = "width:240px" })
                         @Html.ValidationMessageFor(model => model.House.ProvinceID)
                     </div>
                 </div>
                 @*Introduction*@
                 <div class="field" style="float: left">
                     <span class="leftlabel">District(*)</span>
                     <div class="editor-field">
                         <select id="ddldistrict" name="ddldistrict" style="width: 240px">
                             <option value="-1">Select-District</option>
                         </select>
                     </div>
                 </div>
                 @*Type of Homestay*@
                 <div class="field">
                     <span class="leftlabel">Address(*)</span>
                     <div class="editor-field">
                         @Html.TextBoxFor(model => model.House.AddressDetail, new { style = "width:400px" })
                         @Html.ValidationMessageFor(model => model.House.AddressDetail)
                     </div>
                 </div>
      
             </div>
             <div class="infobox" style="height: 570px; width: 700px; margin-left: 10px; float: left;position: relative">
                 <span class="leftlabel" style="width: 200px; margin-bottom: 10px">Locate your house on map</span>
                 <div class="editor-field">
                     @Html.HiddenFor(model => model.House.Ordinate, new { style = "width:140px" })
                 </div>
                 <label style="position: absolute;top:10px;left:280px">(You can click Locate button or double click your location on map)</label>
                 <div>
                     @*<input type="text" id="search_address" value="" style="margin-top: 5px;width: 360px;" readonly="readonly" /> *@
                     
                     <input type="text" id="address_recommend"  value ="" style="display: none" />           
                 </div>
                 <div id="googleMap" style="width: 680px; height: 500px; margin: 10px 10px 10px 10px">
                 </div>
             </div>
             <div class="infobox" style="height: 570px; width: 410px; margin-left: 10px; float: left">
                 <div class="field">
                     <span class="leftlabel">Contact Name (*)</span>
                     <div class="editor-field" style="float: none">
                         @Html.TextBoxFor(model => model.ContactName, new { style = "width:220px" })
                         @Html.ValidationMessageFor(model => model.ContactName, "", new { style = "float:left;margin-left:150px;" })
                     </div>
                 </div>
                 <div class="field">
                     <span class="leftlabel">Mobile Phone (*)</span>
                     <div class="editor-field"  style="float: none">
                         @Html.TextBoxFor(model => model.MobilePhone, new { style = "width:220px" })
                         @Html.ValidationMessageFor(model => model.MobilePhone, "", new { style = "float:left;margin-left:150px;" })
                     </div>
                 </div>
                 <div class="field">
                     <span class="leftlabel">Telephone</span>
                     <div class="editor-field"  style="float: none">
                         @Html.TextBoxFor(model => model.TelePhone, new { style = "width:220px" })
                         @Html.ValidationMessageFor(model => model.TelePhone, "", new { style = "float:left;margin-left:150px;" })
                     </div>
                 </div>
                 <div class="field">
                     <span class="leftlabel">Email (*)</span>
                     <div class="editor-field"  style="float: none">
                         @Html.TextBoxFor(model => model.Email, new { style = "width:220px" })
                         @Html.ValidationMessageFor(model => model.Email, "", new { style = "float:left;margin-left:150px;" })
                     </div>
                 </div>
                 <div style="margin-left: 160px; float: left;margin-top: 10px">
      
                     <input type="submit" value="Save and Continue"  style="width: 120px; background-color: sienna; color: whitesmoke !important; float: right" />
            
                     <input type="reset" value="Reset" onclick="Reset()" style="width: 100px; background-color: sienna; color: whitesmoke !important; float: right; margin-right: 10px" />
           
                 </div>
             </div>


        }
    }
    else
    {
        
        <script type="text/javascript">
            $(function () {

                $('a[data-ajax-update="#dialog"]')[0].click();
                
               
               
            });
        </script>
    }

}
<script type="text/javascript">
        var isvalidtypehouse = false;
       var isvalidprovince = false;
        $('#form').live("submit", function () {

            var selecttypeofhouse = $('#TypeOfHouseID').val();
            var selectprovince = $('#ddlprovince').val();
            var currentUn1 = $('#TypeOfHouseID').next("span");
            var currentUn2 = $('#ddlprovince').next("span");
            if (selecttypeofhouse !== "") {
                isvalidtypehouse = true;
                $(currentUn1).css("display", "none");

            } else {


                $(currentUn1).css("display", "block");
                $(currentUn1).css("color", "red");
                $(currentUn1).html("Choose type of house");
                return false;
            }
            if (selectprovince !== "") {
                isvalidprovince = true;
                $(currentUn2).css("display", "none");

            } else {


                $(currentUn2).css("display", "block");
                $(currentUn2).css("color", "red");
                $(currentUn2).html("Choose province");
                return false;
            }
            
            return true;

        });

//        $('#House_AddressDetail').keydown(function() {
//            var address = $(this).val();
//            $('#search_address').val(address);
//            

//        });
    
</script>